home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / mac / Shout3Ddemo / S3D_2E1.exe / Shout3d_runtime / codebase / custom_nodes / ScreenBoxPickerEffect.java < prev    next >
Text File  |  2000-11-10  |  2KB  |  98 lines

  1. /**
  2.     Company:        Eyematic Interfaces
  3.     Project:        Shout3D Core
  4.     Class:            ScreenBoxPickerEffect
  5.     Date:            November 9, 2000
  6.     Description:    Picks the object under the cursor and draws a screenspace box around it.
  7.     (C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
  8.  */
  9.  
  10. package custom_nodes;
  11.  
  12. import shout3d.core.*;
  13. import shout3d.*;
  14. import shout3d.core.awt.*;
  15. import java.awt.*;
  16. import java.awt.image.*;
  17.  
  18. /**
  19.  * ScreenBoxPickerEffect
  20.  * 
  21.  * @author Paul Isaacs
  22.  * @author Jim Stewartson
  23.  * @author Hugues Labbe
  24.  * 
  25.  */
  26.  
  27. public class ScreenBoxPickerEffect extends PostRenderEffect implements DeviceObserver
  28. {
  29.     Picker picker;
  30.     int x;
  31.     int y;
  32.     boolean mouseIsInPanel = false;
  33.  
  34.     /**
  35.      * Constructs a default DEFNamePickerEffect node.
  36.      */
  37.     public ScreenBoxPickerEffect()
  38.     {
  39.         super();
  40.     }
  41.     
  42.     /**
  43.      * When the viewer is set, register with it to receive DeviceInput.
  44.      */
  45.     public void setViewer(Shout3DViewer v){
  46.         // Unregister with old viewer
  47.         if (getViewer() != null)
  48.             getViewer().getDeviceListener().removeDeviceObserver(this, "MouseInput");
  49.         // Change viewers.        
  50.         super.setViewer(v);
  51.         // Register with new viewer
  52.         if (getViewer() != null){
  53.             getViewer().getDeviceListener().addDeviceObserver(this, "MouseInput", null);
  54.             picker = getViewer().getNewPicker();
  55.         }
  56.     }
  57.  
  58.     public boolean onDeviceInput(DeviceInput di, Object userData)
  59.     {
  60.         if ( !(di instanceof MouseInput))
  61.             return false;
  62.  
  63.         MouseInput mi = (MouseInput)di;
  64.         switch (mi.which) {
  65.             case MouseInput.DOWN:
  66.             case MouseInput.DRAG:
  67.             case MouseInput.MOVE:
  68.                 x = mi.x;
  69.                 y = mi.y;
  70.                 mouseIsInPanel = true;
  71.                 break;
  72.             case MouseInput.ENTER:
  73.                 mouseIsInPanel = true;
  74.                 break;
  75.             case MouseInput.EXIT:
  76.                 mouseIsInPanel = false;
  77.                 break;
  78.             default:
  79.                 break;
  80.         }
  81.         return false;
  82.     }
  83.  
  84.     public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight)
  85.     {
  86.         if (mouseIsInPanel) {
  87.             Node[] node = picker.pickClosest(x, y);
  88.             if (node == null)
  89.                 return;
  90.  
  91.             // Get the screen space bounds of the selection:
  92.             float[] bounds = { 0, 0, 0, 0 };
  93.             if (picker.getProjectedBounds(node,false, bounds)){
  94.                 g.drawRect((int)bounds[0], (int)bounds[1], (int)(bounds[2]-bounds[0]+1), (int)(bounds[3]-bounds[1]+1));
  95.             }
  96.         }
  97.     }
  98. }